package com.tms.springboot.controller;


import com.github.pagehelper.PageInfo;
import com.tms.springboot.base.pojo.PdTruckType;
import com.tms.springboot.search.PdTruckTypeSearch;
import com.tms.springboot.service.PdTruckTypeService;
import com.tms.springboot.utils.UUId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 车辆类型表 前端控制器
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-truck-type")
public class PdTruckTypeController {

    @Autowired
    private PdTruckTypeService pdTruckTypeSevice;

    /**
     * 分页查询车辆类型
     * @param pdTruckerTypeSearch
     * @return
     * @throws Exception
     */
    @RequestMapping("/truckTypePage")
    public PageInfo<PdTruckType> TruckTypePage(@RequestBody PdTruckTypeSearch pdTruckerTypeSearch) throws Exception {

        PageInfo<PdTruckType> pdTruckTypePageInfo = this.pdTruckTypeSevice.truckTypePage(pdTruckerTypeSearch);

        return pdTruckTypePageInfo;

    }

    /**
     * 查询车辆类型
     * @return
     */
    @RequestMapping("/selectTruckType")
    public List<PdTruckType> selectPdtruckType(){

        List<PdTruckType> list = this.pdTruckTypeSevice.list();

        System.out.println(list);

        return list;

    }

    /**
     * 增加车辆类型
     * @param pdTruckType
     * @return
     */
    @RequestMapping("/saveTruckType")
    public boolean saveTruckType(@RequestBody PdTruckType pdTruckType){

        pdTruckType.setId(UUId.nextId());

        pdTruckType.setStatus(1);

        boolean save = this.pdTruckTypeSevice.save(pdTruckType);

        return save;

    }

    /**
     * 修改车辆类型
     * @param pdTruckerType
     * @return
     */
    @RequestMapping("/updateTruckType")
    public boolean updateTruckerType(@RequestBody PdTruckType pdTruckerType){

        boolean update = this.pdTruckTypeSevice.updateById(pdTruckerType);

        return update;

    }

    /**
     * 删除车辆类型
     * @param pdTruckerType
     * @return
     */
    @RequestMapping("/deleteTruckerType")
    public boolean deleteTruckerType(@RequestBody PdTruckType pdTruckerType){

        boolean remove = this.pdTruckTypeSevice.removeById(pdTruckerType.getId());

        return remove;

    }

    /**
     * 根据Id查询车辆类型
     * @param pdTruckerType
     * @return
     */
    @RequestMapping("/selectFindById")
    public PdTruckType selectFindById(@RequestBody  PdTruckType pdTruckerType){

        PdTruckType byId = this.pdTruckTypeSevice.getById(pdTruckerType.getId());

        return byId;

    }

}
